package com.woniu.carrent.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniu.carrent.pojo.TOrder;
import com.woniu.carrent.pojo.dto.TOrderDto;
import com.woniu.carrent.pojo.vo.TOderVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface TOrderMapper extends BaseMapper<TOrder> {
    @Select("select o.orderId AS orderid,o.userId AS userid ,\n" +
            "o.cdId AS cdid ,c.carName as carname,c.pictures,\n" +
            "o.creatTime as creattime,o.endTime as endtime,\n" +
            "o.totalPrice as totalprice , o.isPaid as ispaid,\n" +
            "l.lName AS lname \n" +
            "from t_order o\n" +
            "join t_cardetail cd on o.cdId = cd.cdId\n" +
            "join t_car c on cd.carId = c.carId\n" +
            "join t_location l on l.lId = c.lId\n" +
            "${ew.customSqlSegment}")
    List<TOrder> selectAllByUseridTOrderList( @Param("ew") QueryWrapper<TOrder> queryWrapper);
    @Select("SELECT \n" +
            "    o.*,\n" +
            "    seller.userName AS sellerName,\n" +
            "    buyer.userName AS buyerName,\n" +
            "    c.carName AS carName,\n" +
            "    GROUP_CONCAT(cp.cpImg) AS Photos\n" +
            "FROM t_order o\n" +
            "JOIN t_cardetail cd ON o.cdId = cd.cdId\n" +
            "JOIN t_user seller ON cd.userId = seller.userId\n" +
            "JOIN t_user buyer ON o.userId = buyer.userId\n" +
            "JOIN t_car c ON c.carId = cd.carId\n" +
            "JOIN t_carphoto cp ON cp.cdId = cd.cdId\n" +
            "WHERE seller.userId = #{uid}\n" +
            "GROUP BY \n" +
            "    o.orderId,\n" +
            "    seller.userName,\n" +
            "    buyer.userName,\n" +
            "    c.carName\n" +
            "ORDER BY o.orderId;")
    List<TOderVo> selectOrderByUid(Integer uid);
}
